package com.refusea.train.controller

import com.refusea.train.domain.entity.RichText.Cat.COURSE
import com.refusea.train.domain.entity.RichText.Cat.SCHOOL
import com.refusea.train.domain.entity.RichText.Cat.TEACHER
import com.refusea.train.domain.helper.TemplateHelper
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestParam

/**
 * @author Zhang Yan 2024/4/26
 **/
@Controller
class TemplateController(private val templateHelper: TemplateHelper) {

    @GetMapping("/school/{code}")
    fun school(@PathVariable("code") code: String, model: Model): String {
        return templateHelper.getTemplate(SCHOOL, code, 0, model)
    }

    @GetMapping("/teacher/{code}")
    fun teacher(
        @PathVariable("code") code: String,
        @RequestParam("id", required = false) id: Int?,
        model: Model,
    ): String {
        return templateHelper.getTemplate(TEACHER, code, id?:0, model)
    }

    @GetMapping("/course/{code}")
    fun course(
        @PathVariable("code") code: String,
        @RequestParam("id", required = false) id: Int?,
        model: Model,
    ): String {
        return templateHelper.getTemplate(COURSE, code, id?:0, model)
    }
}
